{#

This file is part of the Sonata package.

(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{% extends 'form_div_layout.html.twig' %}

{#
    Inspired from MopaBootstrapBundle: https://github.com/phiamo/MopaBootstrapBundle
#}

{% block choice_widget_collapsed %}
    {% set attr = attr|merge({'class': attr.class|default('') ~ ' form-control'}) %}
    {{ parent() }}
{% endblock choice_widget_collapsed %}

{% block textarea_widget %}
    {% set attr = attr|merge({'class': attr.class|default('') ~ ' form-control'}) %}
    {{ parent() }}
{% endblock textarea_widget %}

{% block form_widget_simple %}
    {% set attr = attr|merge({'class': attr.class|default('') ~ ' form-control'}) %}
    {{ parent() }}
{% endblock form_widget_simple %}

{% block choice_widget_expanded %}
    {% set label_attr = label_attr|merge({'class': (label_attr.class|default(''))}) %}
    {% set label_attr = label_attr|merge({'class': (label_attr.class ~ ' ' ~ (widget_type is defined and widget_type != '' ? (multiple ? 'checkbox' : 'radio') ~ '-' ~ widget_type : ''))}) %}
    {% if expanded %}
        {% set attr = attr|merge({'class': attr.class|default('')}) %}
        <div {{ block('widget_container_attributes') }}>
    {% endif %}
    {% for child in form %}
        {% if widget_type is defined and widget_type != 'inline' %}
            <div class="{{ multiple ? 'checkbox' : 'radio' }}">
        {% endif %}
        <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
        {{ form_widget(child, {'attr': {'class': attr.widget_class|default('')}}) }}
        {{ child.vars.label|trans({}, translation_domain) }}
        </label>
        {% if widget_type is defined and widget_type != 'inline' %}
            </div>
        {% endif %}
    {% endfor %}
    {% if block('form_message') is defined %}
        {{ block('form_message') }}
    {% endif %}
    {% if expanded %}
        </div>
    {% endif %}
{% endblock choice_widget_expanded %}

{% block checkbox_widget %}
    {% if label is not same as(false) and label is empty %}
        {% set label = name|humanize %}
    {% endif %}
    {% if form.parent != null and 'choice' not in form.parent.vars.block_prefixes %}
        <div class="checkbox">
    {% endif %}

    {% if form.parent != null and 'choice' not in form.parent.vars.block_prefixes and label_render is defined %}
        <label class="{% if inline is defined and inline %}checkbox-inline{% endif %}">
    {% endif %}

    <input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %}/>
    {% if form.parent != null and 'choice' not in form.parent.vars.block_prefixes %}
        {% if label_render is defined and widget_checkbox_label in ['both', 'widget'] %}
            {{ label|trans({}, translation_domain) }}
            </label>
        {% endif %}
    {% endif %}
    {% if form.parent != null and 'choice' not in form.parent.vars.block_prefixes %}
        </div>
        {% if block('form_message') is defined %}
            {{ block('form_message') }}
        {% endif %}
    {% endif %}
{% endblock checkbox_widget %}

{% block sonata_type_model_autocomplete_widget %}
    {% include template %}
{% endblock sonata_type_model_autocomplete_widget %}
